<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/25 13:27
 */

namespace App\Transformers;

use App\Models\MedicalHpi;
use App\Models\MedicalHpiSub;
use League\Fractal\TransformerAbstract;

class HpiTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['sub'];

    public function transform(MedicalHpi $hpi)
    {
        return [
            'id'            => $hpi->id,
            'record_id'     => $hpi->record_id,
            'diet'          => $hpi->diet,
            'sport'         => $hpi->sport,
            'sport_strength'=> $hpi->sport_strength,
            'sport_time'    => $hpi->sport_time,
            'normal'        => $hpi->normal,
            'thyroid'       => $hpi->thyroid,
            'adrenal_gland' => $hpi->adrenal_gland,
            'remark'        => $hpi->remark,
            'created_at'    => $hpi->created_at->toDateTimeString(),
            'updated_at'    => $hpi->updated_at->toDateTimeString(),
        ];
    }

    /**
     * @param \App\Models\MedicalHpi $hpi
     * @return mixed
     */
    public function includeSub(MedicalHpi $hpi)
    {
        $collection = MedicalHpiSub::where(['record_id' => $hpi->record_id])->get();

        return $this->collection($collection, new HpiSubTransformer());
    }
}